<?php 
namespace Admin\Controller;
use Think\Controller; 
class AddController extends BaseController{
	function add(){

$typeOb=D('Wares_type');
		$arr=$typeOb->select();
		function oneps($hz,$pid=0,$level=1){
				//返回onepsall
				$onepsall = array();
				foreach($hz as $v){
					if($v['pid']==$pid){
						$v['level'] = $level;
						$v['html']=str_repeat('&nbsp',($level*5));
						$onepsall[] = $v;
						//oneps($hz,$pid=$v['id'],$level+1)
						$onepsall = array_merge($onepsall,oneps($hz,$v['id'],$level+1));
					}
				}
				return $onepsall;
         }    
         $array = oneps($arr);
        $this->assign('array',$array);
		$this->display();
	}
	function check(){
				if (!empty($_POST)) {
				 $waresTypeOb=D('Wares_entry');
				 $uploadOb = new \Think\Upload();
				 $uploadOb->autoSub=false;
				 $uploadOb->mimes=array('mimes'=>'image/jpeg','image/png','image/gif');
				 $uploadOb->rootPath='./Public/Uploads/';
			     $info=$uploadOb->upload($_FILES);
			     $_POST['wares_images']=$info['wares_images']['savename'];
				 $cRe=$waresTypeOb->create();
				if ($cRe) {
					 $re=$waresTypeOb->add();
					 if ($re) {
					 	  $this->success("添加成功",U("Admin/Lister/lister"));
					 }else{
					 	$this->erroy("添加失败",U("Admin/Add/add"));
					 }
					 exit();
				}else{
					$info=$waresTypeOb->getError();
					//$this->assign('info',$info);
					/*$this->assign('arr',$_POSt);*/
					$infoStr = join('<br>',$info);
					$this->error($info,U("Admin/Add/add"),1);
				}
			}

		}
	}
